package core.actions;

import java.awt.Color;
import java.awt.Point;

import core.*;






public abstract class Action {

	String name;
	String imageName = "iconMove3.png";
	Color color = Color.cyan;
	protected char nameChar=' ';
	SingleButtonGame main;
	//public int masterId;
	public Player master;
	protected boolean needDir=false, needPos=false;
	protected boolean hasDir=false, hasPos=false;
	protected int dirRes=1, dirCount=1;
	protected Point inputPoint;
	protected double inputDir;
	protected int range;
	protected int energyCost;
	protected int value;
	
	
	public Action(){
		main=SingleButtonGame.getInstance();
	}
	
	public void activate(){
		System.out.println("Activating"+toString());
		if(!isReady()){
			System.out.println("Is not ready!");
		}
		if(hasEnoughEnergy()){
			execute();
			master.drainEnergy(energyCost);
			reset();
		}
		
	}
	public String toString(){
		return name;
	}
	public int getValue(){
		return value;
	}
	public char getChar(){
		return nameChar;
	}
	public String getImageName(){
		return imageName;
	}
	public boolean needDir(){
		//Returns true if a direction is needed but doesn't exist
		return (needDir==true && hasDir==false);
	}
	public boolean needPos(){
		//Returns true if a direction is needed but doesn't exist
		return (needPos==true && hasPos==false);
	}
	public boolean isReady(){
		return (!needDir() && !needPos());
	}
	
	public abstract void execute();
	
	public DirectionChoice getDirChoice(){
		DirectionChoice dirChoice = new DirectionChoice(master.getHero());
		if(dirRes != dirCount){ //not first dir
			int pow = dirRes-dirCount;
			dirChoice.setArc(inputDir, 0.09/(pow*pow));
			dirChoice.setSpeed(0.09/(pow*pow));
			dirChoice.setLineRange(400*pow);
		}
		return dirChoice;
	}
	public PositionChoice getPosChoice(){
		
		return new PositionChoice(master.getHero(), range, inputDir);
	}
	public void setInputPoint(Point p){
		inputPoint=p;
		hasPos=true;
	}
	public void setInputDir(double d){
		inputDir=d;
		dirCount--;
		if(dirCount == 0)
			hasDir=true;
	}
	public boolean hasEnoughEnergy(){
		return master.getEnergy()>energyCost;
	}
	public void setOwner(Player p){
		master = p;
	}
	/**
	 * prepares to be called again
	 */
	public void reset(){
		hasPos=false;
		hasDir=false;
		dirCount = dirRes;
	}
	public int getDirRes(){
		return dirRes;
	}
	public int getDirCount(){
		return dirCount;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}
	
}
